package com.cf.mvp.sample.mvp.model;

import android.util.Log;

import com.cf.mvp.mvp.BaseModel;
import com.cf.mvp.rx.BaseErrorObserver;
import com.cf.mvp.sample.mvp.contract.RegisterContract;
import com.cf.mvp.tool.LogUtils;

import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class RegisterModel extends BaseModel<RegisterContract.Presenter> implements RegisterContract.Model {
    @Override
    public void requestRegister(String userName, String pwd) {
        Observable.timer(10, TimeUnit.SECONDS)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseErrorObserver<Long>() {
                    @Override
                    public void onNext(Long aLong) {
                        getPresenter().responseRegister();
                    }
                });
    }

    @Override
    public void requestThread() {
        new Thread(() -> {
            LogUtils.d("延时操作", "开始");
            try {
                Thread.sleep(20 * 1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            getPresenter().responseRegister();
            LogUtils.d("延时操作", "完成");
        }).start();
    }


}
